<template>
	<view class="container">
		
		<view class="intro">公文信息</view>
		<text>编号:{{info.bianhao}}</text>
		<br/>
		<text>收文单位:{{info.danwei}}</text>
		<br/>
		<text>文号:{{info.wenhao}}</text>
		<br/>
		<text>标题:{{info.biaoti}}</text>
		<br/>
		<text>收文日期:{{getShouwenDateStr()}}</text>
		<br/>
		<text>摘要:{{info.zhaiyao}}</text>
		<br/>
		<button type="primary" :disabled="!!info.shoucangId" @click="clickShoucang">{{getShoucangStr()}}</button>
	</view>
</template>

<script>

	import {websock} from '../../net/websock'
	import moment from 'moment'

	export default {
		data() {
			return {
				info: {}
			}
		},
		async onLoad(params) {
			try {
				this.info = await websock.getGongwenInfo({id: params.id})
				console.log('gongwen info', this.info)
			} catch (err) {
				uni.showToast({title: err.message || 'error'})
			}
		},
		methods: {
			getShoucangStr() {
				if (!this.info.shoucangId) return '收藏'
				return '已收藏'
			},
			getShouwenDateStr() {
				return moment(this.info.shouwenDate).format('YYYY-MM-DD')
			},
			async clickShoucang() {
				try {
					await websock.shoucangGongwen({id: this.info.id})
					this.info.shoucangId = 1
				} catch (err) {
					uni.showToast({title: err.message || 'error'})
				}
			}
		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>
